package com.vitabuybuy.tv.ui.mine.talent.task.viewmodel

import androidx.lifecycle.MutableLiveData
import com.vitabuybuy.tv.dto.TaskMenageDetailDto
import com.vitabuybuy.tv.dto.TaskPoolDetailDto
import com.library.common.base.BaseViewModel
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.net.loadingtype.LoadingType
import com.library.common.toast.XToast
import com.vitabuybuy.tv.network.TalentLiveRepository
import com.vitabuybuy.tv.network.TaskRepository

class TaskDetailsViewModel : BaseViewModel() {
    val taskDetails = MutableLiveData<TaskPoolDetailDto>()
    val taskMenageDetails = MutableLiveData<TaskMenageDetailDto>()
    fun getTaskPoolDetails(taskId: Int?) {
        rxHttpRequest {
            onRequest = {
                taskDetails.value = TaskRepository.getTaskDetails(taskId).await()
                statusView.set(LoadingType.SHOW_CONTENT)
            }
            onError = {
                XToast.normal(it.msg)
            }
            isRefresh = true
            isLoadingType = true
        }
    }
    fun getTaskMenagerDetails(taskId: Int?) {
        rxHttpRequest {
            onRequest = {
                taskMenageDetails.value = TaskRepository.getTaskMenagerDetails(taskId).await()
            }
            onError = {
                XToast.normal(it.msg)
            }
        }
    }
    fun getTaskSign(params:Map<String,Any?>) {
        rxHttpRequest {
            onRequest = {
            TaskRepository.getTaskSign(params).await()
                defUI.msgEvent.postValue(MessageModel(1))
            }
            onError = {
                XToast.normal(it.msg)
            }
        }
    }
    fun cancelTaskSign(params:Map<String,Any?>) {
        rxHttpRequest {
            onRequest = {
                TaskRepository.cancelSign(params).await()
                defUI.msgEvent.postValue(MessageModel(1))
            }
            onError = {
                XToast.normal(it.msg)
            }
        }
    }
    fun refuseOrAgreeInvite(params:Map<String,Any?>) {
        rxHttpRequest {
            onRequest = {
                TaskRepository.refuseOrAgreeInvite(params).await()
                defUI.msgEvent.postValue(MessageModel(1))
            }
            onError = {
                XToast.normal(it.msg)
            }
        }
    }
}
